package org.lgiavedoni.android.franq.service.question.dao;

import java.util.List;

import org.lgiavedoni.android.franq.core.dao.AbstractDAO;
import org.lgiavedoni.android.franq.core.dao.DaoObject;
import org.lgiavedoni.android.franq.core.question.Question;

import com.db4o.query.Predicate;

public class QuestionDAO extends AbstractDAO<Question> {

	public static final QuestionDAO inst = new QuestionDAO();

	@Override
	public Class getObjectClass() {
		return Question.class;
	}

	public Question getNextQuestion() {
		List<DaoObject> questions = dbService.query(new Predicate<Question>() {

			@Override
			public boolean match(Question q) {
				return !q.isSolved();
			}
		});

		// TODO improve a sort by priority
		return (Question) (questions == null || questions.size() == 0 ? null : questions.get(0));
	}
}
